package com.bajdcc.LALR1.interpret.module.web

/**
 * 实用方法
 *
 * @author bajdcc
 */
object ModuleNetWebHelper {

    private var mapMime = mutableMapOf<String, String>()

    fun getStatusCodeText(code: Int): String {
        when (code) {
            100 -> return "Continue"
            101 -> return "Switching Protocols"
            102 -> return "Processing"

            200 -> return "OK"
            201 -> return "Created"
            202 -> return "Accepted"
            203 -> return "Non-Authoriative Information"
            204 -> return "No Content"
            205 -> return "Reset Content"
            206 -> return "Partial Content"
            207 -> return "Multi-Status"

            300 -> return "Multiple Choices"
            301 -> return "Moved Permanently"
            302 -> return "Found"
            303 -> return "See Other"
            304 -> return "Not Modified"
            305 -> return "Use Proxy"
            306 -> return "(Unused)"
            307 -> return "Temporary Redirect"

            400 -> return "Bad Request"
            401 -> return "Unauthorized"
            402 -> return "Payment Granted"
            403 -> return "Forbidden"
            404 -> return "Not Found"
            405 -> return "Method Not Allowed"
            406 -> return "Not Acceptable"
            407 -> return "Proxy Authentication Required"
            408 -> return "Request Time-out"
            409 -> return "Conflict"
            410 -> return "Gone"
            411 -> return "Length Required"
            412 -> return "Precondition Failed"
            413 -> return "Request Entity Too Large"
            414 -> return "Request-URI Too Large"
            415 -> return "Unsupported Media Type"
            416 -> return "Requested range not satisfiable"
            417 -> return "Expectation Failed"
            422 -> return "Unprocessable Entity"
            423 -> return "Locked"
            424 -> return "Failed Dependency"

            500 -> return "Internal Server Error"
            501 -> return "Not Implemented"
            502 -> return "Bad Gateway"
            503 -> return "Service Unavailable"
            504 -> return "Gateway Timeout"
            505 -> return "HTTP Version Not Supported"
            507 -> return "Insufficient Storage"
        }
        return "Unknown"
    }

    fun getMimeByExtension(ext: String?): String {
        if (mapMime.isEmpty()) {
            mapMime["323"] = "text/h323"
            mapMime["acx"] = "application/internet-property-stream"
            mapMime["ai"] = "application/postscript"
            mapMime["aif"] = "audio/x-aiff"
            mapMime["aifc"] = "audio/x-aiff"
            mapMime["aiff"] = "audio/x-aiff"
            mapMime["asf"] = "video/x-ms-asf"
            mapMime["asr"] = "video/x-ms-asf"
            mapMime["asx"] = "video/x-ms-asf"
            mapMime["au"] = "audio/basic"
            mapMime["avi"] = "video/x-msvideo"
            mapMime["axs"] = "application/olescript"
            mapMime["bas"] = "text/plain"
            mapMime["bcpio"] = "application/x-bcpio"
            mapMime["bin"] = "application/octet-stream"
            mapMime["bmp"] = "image/bmp"
            mapMime["c"] = "text/plain"
            mapMime["cat"] = "application/vnd.ms-pkiseccat"
            mapMime["cdf"] = "application/x-cdf"
            mapMime["cer"] = "application/x-x509-ca-cert"
            mapMime["class"] = "application/octet-stream"
            mapMime["clp"] = "application/x-msclip"
            mapMime["cmx"] = "image/x-cmx"
            mapMime["cod"] = "image/cis-cod"
            mapMime["cpio"] = "application/x-cpio"
            mapMime["crd"] = "application/x-mscardfile"
            mapMime["crl"] = "application/pkix-crl"
            mapMime["crt"] = "application/x-x509-ca-cert"
            mapMime["csh"] = "application/x-csh"
            mapMime["css"] = "text/css"
            mapMime["dcr"] = "application/x-director"
            mapMime["der"] = "application/x-x509-ca-cert"
            mapMime["dir"] = "application/x-director"
            mapMime["dll"] = "application/x-msdownload"
            mapMime["dms"] = "application/octet-stream"
            mapMime["doc"] = "application/msword"
            mapMime["dot"] = "application/msword"
            mapMime["dvi"] = "application/x-dvi"
            mapMime["dxr"] = "application/x-director"
            mapMime["eps"] = "application/postscript"
            mapMime["etx"] = "text/x-setext"
            mapMime["evy"] = "application/envoy"
            mapMime["exe"] = "application/octet-stream"
            mapMime["fif"] = "application/fractals"
            mapMime["flr"] = "x-world/x-vrml"
            mapMime["gif"] = "image/gif"
            mapMime["gtar"] = "application/x-gtar"
            mapMime["gz"] = "application/x-gzip"
            mapMime["h"] = "text/plain"
            mapMime["hdf"] = "application/x-hdf"
            mapMime["hlp"] = "application/winhlp"
            mapMime["hqx"] = "application/mac-binhex40"
            mapMime["hta"] = "application/hta"
            mapMime["htc"] = "text/x-component"
            mapMime["htm"] = "text/html"
            mapMime["html"] = "text/html"
            mapMime["html-utf8"] = "text/html;charset=utf-8"
            mapMime["htt"] = "text/webviewhtml"
            mapMime["ico"] = "image/x-icon"
            mapMime["ief"] = "image/ief"
            mapMime["iii"] = "application/x-iphone"
            mapMime["ins"] = "application/x-internet-signup"
            mapMime["isp"] = "application/x-internet-signup"
            mapMime["jfif"] = "image/pipeg"
            mapMime["jpe"] = "image/jpeg"
            mapMime["jpeg"] = "image/jpeg"
            mapMime["jpg"] = "image/jpeg"
            mapMime["js"] = "application/x-javascript"
            mapMime["latex"] = "application/x-latex"
            mapMime["lha"] = "application/octet-stream"
            mapMime["lsf"] = "video/x-la-asf"
            mapMime["lsx"] = "video/x-la-asf"
            mapMime["lzh"] = "application/octet-stream"
            mapMime["m13"] = "application/x-msmediaview"
            mapMime["m14"] = "application/x-msmediaview"
            mapMime["m3u"] = "audio/x-mpegurl"
            mapMime["man"] = "application/x-troff-man"
            mapMime["mdb"] = "application/x-msaccess"
            mapMime["me"] = "application/x-troff-me"
            mapMime["mht"] = "message/rfc822"
            mapMime["mhtml"] = "message/rfc822"
            mapMime["mid"] = "audio/mid"
            mapMime["mny"] = "application/x-msmoney"
            mapMime["mov"] = "video/quicktime"
            mapMime["movie"] = "video/x-sgi-movie"
            mapMime["mp2"] = "video/mpeg"
            mapMime["mp3"] = "audio/mpeg"
            mapMime["mpa"] = "video/mpeg"
            mapMime["mpe"] = "video/mpeg"
            mapMime["mpeg"] = "video/mpeg"
            mapMime["mpg"] = "video/mpeg"
            mapMime["mpp"] = "application/vnd.ms-project"
            mapMime["mpv2"] = "video/mpeg"
            mapMime["ms"] = "application/x-troff-ms"
            mapMime["mvb"] = "application/x-msmediaview"
            mapMime["nws"] = "message/rfc822"
            mapMime["oda"] = "application/oda"
            mapMime["p10"] = "application/pkcs10"
            mapMime["p12"] = "application/x-pkcs12"
            mapMime["p7b"] = "application/x-pkcs7-certificates"
            mapMime["p7c"] = "application/x-pkcs7-mime"
            mapMime["p7m"] = "application/x-pkcs7-mime"
            mapMime["p7r"] = "application/x-pkcs7-certreqresp"
            mapMime["p7s"] = "application/x-pkcs7-signature"
            mapMime["pbm"] = "image/x-portable-bitmap"
            mapMime["pdf"] = "application/pdf"
            mapMime["pfx"] = "application/x-pkcs12"
            mapMime["pgm"] = "image/x-portable-graymap"
            mapMime["pko"] = "application/ynd.ms-pkipko"
            mapMime["pma"] = "application/x-perfmon"
            mapMime["pmc"] = "application/x-perfmon"
            mapMime["pml"] = "application/x-perfmon"
            mapMime["pmr"] = "application/x-perfmon"
            mapMime["pmw"] = "application/x-perfmon"
            mapMime["pnm"] = "image/x-portable-anymap"
            mapMime["pot"] = "application/vnd.ms-powerpoint"
            mapMime["ppm"] = "image/x-portable-pixmap"
            mapMime["pps"] = "application/vnd.ms-powerpoint"
            mapMime["ppt"] = "application/vnd.ms-powerpoint"
            mapMime["prf"] = "application/pics-rules"
            mapMime["ps"] = "application/postscript"
            mapMime["pub"] = "application/x-mspublisher"
            mapMime["qt"] = "video/quicktime"
            mapMime["ra"] = "audio/x-pn-realaudio"
            mapMime["ram"] = "audio/x-pn-realaudio"
            mapMime["ras"] = "image/x-cmu-raster"
            mapMime["rgb"] = "image/x-rgb"
            mapMime["rmi"] = "audio/mid"
            mapMime["roff"] = "application/x-troff"
            mapMime["rtf"] = "application/rtf"
            mapMime["rtx"] = "text/richtext"
            mapMime["scd"] = "application/x-msschedule"
            mapMime["sct"] = "text/scriptlet"
            mapMime["setpay"] = "application/set-payment-initiation"
            mapMime["setreg"] = "application/set-registration-initiation"
            mapMime["sh"] = "application/x-sh"
            mapMime["shar"] = "application/x-shar"
            mapMime["sit"] = "application/x-stuffit"
            mapMime["snd"] = "audio/basic"
            mapMime["spc"] = "application/x-pkcs7-certificates"
            mapMime["spl"] = "application/futuresplash"
            mapMime["src"] = "application/x-wais-source"
            mapMime["sst"] = "application/vnd.ms-pkicertstore"
            mapMime["stl"] = "application/vnd.ms-pkistl"
            mapMime["stm"] = "text/html"
            mapMime["svg"] = "image/svg+xml"
            mapMime["sv4cpio"] = "application/x-sv4cpio"
            mapMime["sv4crc"] = "application/x-sv4crc"
            mapMime["swf"] = "application/x-shockwave-flash"
            mapMime["t"] = "application/x-troff"
            mapMime["tar"] = "application/x-tar"
            mapMime["tcl"] = "application/x-tcl"
            mapMime["tex"] = "application/x-tex"
            mapMime["texi"] = "application/x-texinfo"
            mapMime["texinfo"] = "application/x-texinfo"
            mapMime["tgz"] = "application/x-compressed"
            mapMime["tif"] = "image/tiff"
            mapMime["tiff"] = "image/tiff"
            mapMime["tr"] = "application/x-troff"
            mapMime["trm"] = "application/x-msterminal"
            mapMime["tsv"] = "text/tab-separated-values"
            mapMime["txt"] = "text/plain"
            mapMime["uls"] = "text/iuls"
            mapMime["ustar"] = "application/x-ustar"
            mapMime["vcf"] = "text/x-vcard"
            mapMime["vrml"] = "x-world/x-vrml"
            mapMime["wav"] = "audio/x-wav"
            mapMime["wcm"] = "application/vnd.ms-works"
            mapMime["wdb"] = "application/vnd.ms-works"
            mapMime["wks"] = "application/vnd.ms-works"
            mapMime["wmf"] = "application/x-msmetafile"
            mapMime["wps"] = "application/vnd.ms-works"
            mapMime["wri"] = "application/x-mswrite"
            mapMime["wrl"] = "x-world/x-vrml"
            mapMime["wrz"] = "x-world/x-vrml"
            mapMime["xaf"] = "x-world/x-vrml"
            mapMime["xbm"] = "image/x-xbitmap"
            mapMime["xla"] = "application/vnd.ms-excel"
            mapMime["xlc"] = "application/vnd.ms-excel"
            mapMime["xlm"] = "application/vnd.ms-excel"
            mapMime["xls"] = "application/vnd.ms-excel"
            mapMime["xlt"] = "application/vnd.ms-excel"
            mapMime["xlw"] = "application/vnd.ms-excel"
            mapMime["xof"] = "x-world/x-vrml"
            mapMime["xpm"] = "image/x-xpixmap"
            mapMime["xwd"] = "image/x-xwindowdump"
            mapMime["z"] = "application/x-compress"
            mapMime["zip"] = "application/zip"
        }
        return if (ext == null || ext.isEmpty()) {
            "application/octet-stream"
        } else mapMime.getOrDefault(ext, "application/octet-stream")
    }
}
